home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  14.2 KB  |  536 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 2 $ 
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef SELECTION_H
  27. #include "Selection.h"
  28. #endif
  29.  
  30. #ifndef TRACKER_H
  31. #include "Tracker.h"
  32. #endif
  33.  
  34. #ifndef COMMANDS_H
  35. #include "Commands.h"
  36. #endif
  37.  
  38. #ifndef LINKING_H
  39. #include "Linking.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. #ifndef VIEW_H
  47. #include "View.h"
  48. #endif
  49.  
  50. // ----- Framework Layer -----
  51.  
  52. #ifndef FWFCTCLP_H
  53. #include "FWFctClp.h"
  54. #endif
  55.  
  56. #ifndef FWCLPCMD_H
  57. #include "FWClpCmd.h"
  58. #endif
  59.  
  60. #ifndef FWPROXY_H
  61. #include "FWProxy.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWITERS_H
  69. #include "FWIters.h"
  70. #endif
  71.  
  72. #ifndef FWLNKITE_H
  73. #include "FWLnkIte.h"
  74. #endif
  75.  
  76. #ifndef FWGROWBX_H
  77. #include "FWGrowBx.h"
  78. #endif
  79.  
  80. #ifndef FWSCLBAR_H
  81. #include "FWSclBar.h"
  82. #endif
  83.  
  84. // ----- OS Layer -----
  85.  
  86. #ifndef FWEVENT_H
  87. #include "FWEvent.h"
  88. #endif
  89.  
  90. #ifndef FWMNUBAR_H
  91. #include "FWMnuBar.h"
  92. #endif
  93.  
  94. #ifndef FWPOINT_H
  95. #include "FWPoint.h"
  96. #endif
  97.  
  98. #ifndef FWRECSHP_H
  99. #include "FWRecShp.h"
  100. #endif
  101.  
  102. #ifndef FWRECT_H
  103. #include "FWRect.h"
  104. #endif
  105.  
  106. #ifndef FWCFMRES_H
  107. #include "FWCFMRes.h"
  108. #endif
  109.  
  110. #ifndef FWRGNSHP_H
  111. #include "FWRgnShp.h"
  112. #endif
  113.  
  114. #ifndef FWODGEOM_H
  115. #include "FWODGeom.h"
  116. #endif
  117.  
  118. #ifndef FWCURSOR_H
  119. #include "FWCursor.h"
  120. #endif
  121.  
  122. #ifndef FWCONTXT_H
  123. #include "FWContxt.h"
  124. #endif
  125.  
  126. #ifndef FWEVEDEF_H
  127. #include "FWEveDef.h"
  128. #endif
  129.  
  130. // ----- Foundation Layer -----
  131.  
  132. #ifndef FWORDCOL_H
  133. #include "FWOrdCol.h"
  134. #endif
  135.  
  136. // ----- OpenDoc Includes -----
  137.  
  138. #ifndef SOM_ODClipboard_xh
  139. #include <Clipbd.xh>
  140. #endif
  141.  
  142. #ifndef SOM_ODDragItemIterator_xh
  143. #include <DgItmIt.xh>
  144. #endif
  145.  
  146. #ifndef SOM_ODDragAndDrop_xh
  147. #include <DragDrp.xh>
  148. #endif
  149.  
  150. #ifndef FWODTYPS_H
  151. #include "FWODTyps.h"
  152. #endif
  153.  
  154. #ifndef SOM_Module_OpenDoc_StdProps_defined
  155. #include <StdProps.xh>
  156. #endif
  157.  
  158. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  159. #include <StdTypes.xh>
  160. #endif
  161.  
  162. #ifndef SOM_ODStorageUnit_xh
  163. #include <StorageU.xh>
  164. #endif
  165.  
  166. #ifndef SOM_ODTransform_xh
  167. #include <Trnsform.xh>
  168. #endif
  169.  
  170. #ifndef SOM_ODSession_xh
  171. #include <ODSessn.xh>
  172. #endif
  173.  
  174. #ifndef SOM_ODDispatcher_xh
  175. #include <Disptch.xh>
  176. #endif
  177.  
  178. // ----- Macintosh Toolbox Includes -----
  179.  
  180. #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
  181. #include <Resources.h>
  182. #endif
  183.  
  184. //========================================================================================
  185. // RunTime Info
  186. //========================================================================================
  187.  
  188. #ifdef FW_BUILD_MAC
  189. #pragma segment odfTable
  190. #endif
  191.  
  192. FW_DEFINE_AUTO(CTableFrame)
  193.  
  194. //========================================================================================
  195. //    class CTableFrame
  196. //========================================================================================
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    CTableFrame::CTableFrame
  200. //----------------------------------------------------------------------------------------
  201.  
  202. CTableFrame::CTableFrame(Environment* ev, 
  203.                         ODFrame* odFrame, 
  204.                         FW_CPresentation* presentation, 
  205.                         CTablePart* tablePart,
  206.                         CTablePartContent* tableContent) :
  207.     FW_CEmbeddingFrame(ev, odFrame, presentation, tablePart),
  208.     FW_MDraggableFrame(ev, this),
  209.     FW_MDroppableFrame(ev, this),
  210.     fTablePart(tablePart),
  211.     fTableContent(tableContent),
  212.     fTableView(NULL)
  213. {
  214.     ChangeDroppableState(ev, FW_kFrameDroppable);
  215.     fDraggedCell.fX = fDraggedCell.fY = -1;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    CTableFrame::~CTableFrame
  220. //----------------------------------------------------------------------------------------
  221.  
  222. CTableFrame::~CTableFrame()
  223. {
  224. }
  225.  
  226. //----------------------------------------------------------------------------------------
  227. //    CTableFrame::GetSelection
  228. //----------------------------------------------------------------------------------------
  229.  
  230. CTableSelection* CTableFrame::GetSelection(Environment* ev) const
  231. {
  232.     return (CTableSelection*)GetPresentation(ev)->GetSelection(ev);
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    CTableFrame::CanAcceptDrop
  237. //----------------------------------------------------------------------------------------
  238. // As an embedding frame I can accept anything
  239.  
  240. ODDragResult CTableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  241. {
  242. FW_UNUSED(ev);
  243. FW_UNUSED(dragInfo);
  244.     return TRUE;
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    CTableFrame::DoVirtualKey
  249. //----------------------------------------------------------------------------------------
  250.  
  251. FW_Handled CTableFrame::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
  252. {
  253.     FW_Handled    wasHandled = FW_kNotHandled;
  254.     CCell        cell = this->GetSelection(ev)->GetSelectedCell();
  255.     CCell        size = fTableContent->GetMaxRowCol();
  256.     
  257.     switch (theVirtualKeyEvent.GetKeyCode(ev))
  258.     {
  259.         case FW_kVKLeft:
  260.             if(cell.fX > 0)
  261.             {
  262.                 cell.fX -= 1;
  263.                 this->SelectCell(ev, cell);
  264.                 wasHandled = FW_kHandled;
  265.             }
  266.             break;
  267.         case FW_kVKRight:
  268.             if(cell.fX < size.fX - 1)
  269.             {
  270.                 cell.fX += 1;
  271.                 this->SelectCell(ev, cell);
  272.                 wasHandled = FW_kHandled;
  273.             }
  274.             break;
  275.         case FW_kVKUp:
  276.             if(cell.fY > 0)
  277.             {
  278.                 cell.fY -= 1;
  279.                 this->SelectCell(ev, cell);
  280.                 wasHandled = FW_kHandled;
  281.             }
  282.             break;
  283.         case FW_kVKDown:
  284.             if(cell.fY < size.fY - 1)
  285.             {
  286.                 cell.fY += 1;
  287.                 this->SelectCell(ev, cell);
  288.                 wasHandled = FW_kHandled;
  289.             }
  290.             break;
  291.  
  292.         case FW_kVKBackspace:
  293.         case FW_kVKClear:
  294.             FW_CClipboardCommand* cmd = this->NewClipboardCommand(ev, kODCommandClear);
  295.             if (cmd)
  296.             {
  297.                 cmd->Execute(ev);
  298.                 wasHandled = FW_kHandled;
  299.             }
  300.             break;
  301.     }
  302.  
  303.     return wasHandled;
  304. }
  305.     
  306. //----------------------------------------------------------------------------------------
  307. //    CTableFrame::DoMouseDownInEmbeddedFrameBorder
  308. //----------------------------------------------------------------------------------------
  309.  
  310. FW_Handled CTableFrame::DoMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  311. {
  312.     FW_Handled result = FW_kNotHandled;
  313.     
  314.     if (fTableView->IsGridShown(ev) && this->Drag(ev, theBorderMouseEvent))
  315.         result = FW_kHandled;
  316.     
  317.     return result;
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. //    CTableFrame::SelectCell
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void CTableFrame::SelectCell(Environment* ev, const CCell& cell)
  325. {
  326.     GetSelection(ev)->Select(ev, cell);
  327. }
  328.  
  329. //----------------------------------------------------------------------------------------
  330. // CTableFrame::GetContentRect
  331. //----------------------------------------------------------------------------------------
  332.  
  333. FW_CRect CTableFrame::GetContentRect(Environment* ev) const
  334. {
  335.     FW_CRect contentRect = GetBounds(ev);
  336.  
  337.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  338.     
  339.     contentRect.bottom -= sbSize.y;
  340.     contentRect.right -= sbSize.x;
  341.     
  342.     return contentRect;
  343. }
  344.  
  345. //----------------------------------------------------------------------------------------
  346. //    CTableFrame::Drag
  347. //----------------------------------------------------------------------------------------
  348.  
  349. FW_Handled CTableFrame::Drag(Environment* ev, const FW_CMouseEvent& event)
  350. {
  351.     fDraggedCell = GetSelection(ev)->GetSelectedCell();
  352.     
  353.     FW_Boolean result = FW_MDraggableFrame::Drag(ev, event);
  354.     
  355.     fDraggedCell.fX = fDraggedCell.fY = -1;
  356.     
  357.     return result;
  358. }
  359.  
  360. //----------------------------------------------------------------------------------------
  361. //    CTableFrame::FocusStateChanged
  362. //----------------------------------------------------------------------------------------
  363.  
  364. void CTableFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  365. {    
  366.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  367.  
  368.     if (focus == FW_CPart::fgSelectionFocusToken)
  369.     {
  370.         fTableView->ChangeHighlightState(ev, newState ? kODFullHighlight : kODDimHighlight);
  371.     }
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. //    CTableFrame::NewDropCommand
  376. //----------------------------------------------------------------------------------------
  377.  
  378. FW_CDropCommand* CTableFrame::NewDropCommand(Environment* ev,
  379.                                             FW_CFrame* frame,
  380.                                             ODDragItemIterator* dropInfo, 
  381.                                             ODFacet* odFacet, 
  382.                                             const FW_CPoint& dropPoint)
  383. {
  384. FW_UNUSED(frame);
  385.     FW_ASSERT(frame == this);
  386.     
  387.     CCell dropCell;
  388.     ETableLoc loc = fTableContent->HitTest(ev, dropPoint, dropCell);
  389.  
  390.     if (loc != kTLCell || dropCell == fDraggedCell || fTableContent->CellToProxy(dropCell) != NULL)    // If alreay a proxy gave up
  391.         return NULL;
  392.     else
  393.         return FW_NEW(CCellDropCommand, (ev, fTablePart, fTableContent, this,
  394.                                          dropInfo, odFacet, dropPoint,
  395.                                         dropCell, fDraggedCell));
  396. }
  397.  
  398. //----------------------------------------------------------------------------------------
  399. //    CTableFrame::NewDropTracker
  400. //----------------------------------------------------------------------------------------
  401.  
  402. FW_CDropTracker* CTableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
  403. {
  404.     return new CTableDropTracker(ev, fTablePart, fTableContent, (CTableView*)view, facet, fDraggedCell);
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. // CTableFrame::NewClipboardCommand
  409. //----------------------------------------------------------------------------------------
  410.  
  411. FW_CClipboardCommand* CTableFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  412. {
  413.     return FW_NEW(CTableEditCommand, (ev,
  414.                                       commandID,
  415.                                       fTablePart,
  416.                                       fTableContent,
  417.                                       this,
  418.                                       this->GetSelection(ev)));
  419. }
  420.  
  421. //----------------------------------------------------------------------------------------
  422. // CTableFrame::NewDragCommand
  423. //----------------------------------------------------------------------------------------
  424.  
  425. FW_CDragCommand* CTableFrame::NewDragCommand(Environment* ev, 
  426.                                              FW_CFrame* theFrame,
  427.                                              const FW_CMouseEvent& theMouseEvent)
  428. {
  429. FW_UNUSED(theMouseEvent);
  430.     return FW_NEW(CCellDragCommand, (ev, fTableContent, theFrame, this->GetSelection(ev)));
  431. }
  432.  
  433. //----------------------------------------------------------------------------------------
  434. //    CTableFrame::NewInsertCommand
  435. //----------------------------------------------------------------------------------------
  436. FW_CInsertCommand* CTableFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  437. {
  438.     return FW_NEW(CTableInsertCommand, (ev,
  439.                                         this,
  440.                                         fileSpec,
  441.                                         fTablePart,
  442.                                         GetSelection(ev)->GetSelectedCell()));
  443. }
  444.  
  445. //----------------------------------------------------------------------------------------
  446. // CTableFrame::MoveProxy
  447. //----------------------------------------------------------------------------------------
  448.  
  449. void CTableFrame::MoveProxy(Environment* ev, CTableProxy* proxy, const CCell& destCell)
  450. {
  451.     // Invalidate the source cell
  452.     FW_CRect rect;
  453.     CCell srcCell = proxy->GetCell();
  454.     fTableContent->FindRect(srcCell, rect);
  455.     this->GetPresentation(ev)->Invalidate(ev, rect);
  456.  
  457.     proxy->MoveEmbeddedFrames(ev, destCell);
  458.     proxy->SetCell(destCell);
  459.     this->SelectCell(ev, destCell);
  460.  
  461.     // Invalidate the destination cell
  462.     fTableContent->FindRect(destCell, rect);
  463.     this->GetPresentation(ev)->Invalidate(ev, rect);
  464.  
  465. }
  466.  
  467. //---------------------------------------------------------------------------------------
  468. //    CTableFrame::FacetAdded
  469. //---------------------------------------------------------------------------------------
  470.  
  471. void CTableFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  472. {
  473.     FW_CEmbeddingFrame::FacetAdded(ev, facet, facetCount);    // call inherited
  474.  
  475.     if (facetCount == 1)
  476.         fTablePart->DoPostCreate(ev);
  477. }
  478.  
  479. //----------------------------------------------------------------------------------------
  480. //    CTableFrame::PostCreateViewFromStream
  481. //----------------------------------------------------------------------------------------
  482. // PostCreateViewFromStream is called after subviews are created from resources.  
  483. // Add code which cannot be handled by current resource types.
  484.  
  485. void CTableFrame::PostCreateViewFromStream(Environment* ev)
  486. {
  487.     fTableView = (CTableView*)FindViewByID(ev, kTableViewID);
  488.  
  489.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  490.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  491.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);    
  492.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);    
  493. }
  494.  
  495. //----------------------------------------------------------------------------------------
  496. // CTableFrame::FrameShapeChanged
  497. //----------------------------------------------------------------------------------------
  498. //    My content view size has changed I need to clip my embedded facets.
  499.  
  500. void CTableFrame::FrameShapeChanged(Environment* ev)
  501. {
  502.     FW_CEmbeddingFrame::FrameShapeChanged(ev);
  503.     
  504.     FW_CFacetClipper facetClipper;
  505.     facetClipper.Clip(ev, this);
  506. }
  507.  
  508. //----------------------------------------------------------------------------------------
  509. // CTableFrame::AdjustZoomedWindowSize
  510. //----------------------------------------------------------------------------------------
  511. //    proposedSize is the interior size of the window
  512.  
  513. void CTableFrame::AdjustZoomedWindowSize(Environment *ev, FW_CPoint& proposedSize)
  514. {
  515. FW_UNUSED(ev);
  516.     proposedSize = GetContentView(ev)->GetExtent(ev) + FW_CScrollBar::GetDefaultScrollBarSize();
  517. }
  518.  
  519. //----------------------------------------------------------------------------------------
  520. // CTableFrame::AdjustContentViewSize
  521. //----------------------------------------------------------------------------------------
  522.  
  523. void CTableFrame::AdjustContentViewSize(Environment* ev, FW_ERedrawVerb redraw)
  524. {
  525.     FW_CRect contentRect = GetContentRect(ev);    
  526.  
  527.     FW_CPoint drawingSize = fTableContent->GetExtent();
  528.     
  529.     FW_CPoint drawViewSize(FW_Minimum(drawingSize.x, contentRect.Width()),
  530.                             FW_Minimum(drawingSize.y, contentRect.Height()));
  531.  
  532.     FW_CPoint currentSize = GetContentView(ev)->GetSize(ev);
  533.     if (currentSize != drawViewSize)
  534.         GetContentView(ev)->SetSize(ev, drawViewSize, redraw);
  535. }
  536.